<?php
/**
 * Created by JetBrains PhpStorm.
 * User: CGP
 * Date: 13-10-11
 * Time: 下午3:53
 * 一个超级简单的生成模板类
 * 用法：$data = array(
 * 'a'=>array(
 *  array('title'=>'abc','id'=>1),
 *  array('title'=>'def','id'=>2),
 *  array('title'=>'ghi','id'=>3),
 *  )
 * );
 * $tpl = new EasyTplEngine('_box_of_d.php');
 * if($tpl->SetData($data)){
 *  $str = $tpl->Render();
 *  $tpl->InitHtml('lll.html');
 *  echo $str;
 * }
 * else {
 *  echo 'File Not Exist';
 * }
 */
class IdiotTplEngine {
    private $output = '';
    private $file;
    public function __construct($file) {
        ob_start();
        $this->file = $file;
    }
    /**
     * 设置模板数据
     * @param $data
     * @return bool
     */
    public function SetData($data){
//        echo $this->file;
        if(file_exists($this->file)) {
            include $this->file;
            $this->output = ob_get_contents();
            ob_clean();
            return true;
        }
        return false;
    }
    /**
     * 输出字符串
     * @return string
     */
    public function Render() {
        return $this->output;
    }
    /**
     * 生成静态文件
     * @param $filename 文件名
     * @return int
     */
    public function InitHtml($filename) {
        return file_put_contents($filename, $this->output);
    }
    /**
     * 销毁缓冲区
     */
    public function __destruct() {

    }
}#EOF CLASS
